home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr22 / savag387.zip / SAV387.ASM next >
Assembly Source File  |  1993-05-06  |  1KB  |  86 lines

  1. PAGE    66,132
  2. ;    
  3. ;    SAV_387.ASM    Ray Berry, 2/21/90
  4. ;            CIS 73407,3152
  5. ;            uucp  ...ole!ray
  6. ;
  7. ;    An assembly language 80387 implementation of the 'savage' 
  8. ;    floating point     benchmark.  This module will *not* execute 
  9. ;    properly on 8087/80287 chips.
  10. ;
  11. ;    the code:
  12. ;    
  13. ;    double a = 1.0;
  14. ;    for(i=0; i<2500; i++)
  15. ;        a=tan(atan(exp(log(sqrt(a*a)))))+1.0;
  16. ;
  17.     .MODEL    small, c
  18.  
  19.     .DATA
  20. scratch    DW    ?
  21. result    DQ    ?
  22. a    DQ    1.0
  23. PUBLIC    result
  24.  
  25.     .CODE
  26. savage    proc
  27.  
  28.     ; first init FPU and set rounding mode to 'floor'.  This is
  29.     ; used for the exponentiation code.
  30.  
  31.     finit
  32.     fstcw    scratch
  33.     fwait
  34.     or    byte ptr scratch+1, 0C0H
  35.     fldcw    scratch
  36.  
  37.     mov    cx, 25000    ; iteration counter
  38.     cld
  39.     fld    qword ptr a    ; 'a' is carried on FPU stack throughout
  40.  
  41.     ; turn crank
  42. doloop:
  43.     fld    st        ; dup a
  44.     fmul            ; a*a
  45.     
  46.     fsqrt            ; sqrt
  47.  
  48.     fldln2            ; log base e
  49.     fxch
  50.     fyl2x
  51.  
  52.     ; exp - requires a bit of fooling around, since the 387 limits
  53.     ; its exponentiation arguments to +/- 1.
  54.  
  55.     fldl2e            ; scale for base e
  56.     fmul
  57.     fld    st        ; copy arg
  58.     frndint            ; drop frac part, result is scale factor
  59.     fsub    st(1), st    ; sub int(x) from x
  60.     fxch            ; frac part on TOS
  61.     f2xm1            ; compute 2^x-1
  62.     fld1            ; add the 1
  63.     fadd
  64.     fscale            ; scale according to orig argument
  65.     fstp    st(1)        ; pop the scale factor
  66.  
  67.     ; atan
  68.     fld1
  69.     fpatan            ; arg is st1/st
  70.  
  71.     ; tan
  72.     fptan            ; result is y/x = st1/st
  73.     fdiv
  74.  
  75.     ; plus 1.0
  76.     fld1
  77.     fadd
  78.  
  79.     loop    doloop
  80.  
  81.     fstp    result
  82.     ret
  83.  
  84. savage    endp
  85.     END
  86.